package com.geek.factory.mapper;

import com.geek.factory.entity.Orders;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author author
 * @since 2025-06-19
 */
public interface OrdersMapper extends BaseMapper<Orders> {
    @Insert("<script>" +
            "INSERT INTO order_contract(order_id, contract_id) VALUES " +
            "<foreach collection='contractIds' item='contractId' separator=','>" +
            "(#{orderId}, #{contractId})" +
            "</foreach>" +
            "</script>")
    int saveOrderContracts(@Param("orderId") Long orderId,
                           @Param("contractIds") Integer[] contractIds);

    @Delete("DELETE FROM order_contract WHERE order_id = #{orderId}")
    int deleteOrderContracts(@Param("orderId") Long orderId);

    @Select("SELECT contract_id FROM order_contract WHERE order_id = #{orderId}")
    List<Integer> findContractIdsByOrderId(@Param("orderId") Long orderId);
}
